xlv.obj.pages={
	extend:function(){
	},
	implement:function(){
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.pages');
		return div;			
	},
	properties:{
		pages:10,
		currentPageText:'current page',
		separator:' / ',
		totalPageText:'total pages'
	},
	method:{
		construct:function(){
			Element.addClassName(this,'class_pages');
			var v=this.$V,div,span;
			div = document.createElement('div');
			div.setAttribute('id', 'xlvid_pages_container');
			this.styleFor(div, div.id);
			var clear = div.appendChild(document.createElement('div'));
			clear.style.clear='both';
			span=div.appendChild(document.createElement('img'));
			span.setAttribute('id', 'xlvid_next_page');
			span.setAttribute('height','24');
			span.src='/xlive/images/pages/rightArrow.png';
			this.styleFor(span, span.id);
			v.nextFlip=span=div.appendChild(document.createElement('span'));
			span.setAttribute('id', 'xlvid_next_flip');
			span.innerHTML='...';
			this.styleFor(span, span.id);
			v.pages=[];
			for(var i=0;i<this.$P.pages;++i){
				span=div.appendChild(document.createElement('span'));
				span.setAttribute('id', 'xlvid_page');
				span.innerHTML=(this.$P.pages-i);
				this.styleFor(span, span.id);
				v.pages.unshift(span);
			}
			v.prevFlip=span=div.appendChild(document.createElement('span'));
			span.setAttribute('id', 'xlvid_prev_flip');
			span.innerHTML='...';
			this.styleFor(span, span.id);
			
			span=div.appendChild(document.createElement('img'));
			span.setAttribute('id', 'xlvid_prev_page');
			span.setAttribute('height','24');
			span.src='/xlive/images/pages/leftArrow.png';
			this.styleFor(span, span.id);

			v.pageText=span=div.appendChild(document.createElement('span'));
			span.setAttribute('id', 'xlvid_pagetext');
			this.styleFor(span, span.id);
			var clear = div.appendChild(document.createElement('div'));
			clear.style.clear='both';
			this.appendChild(div);
		},
		initial:function(){
			var v=this.$V;
			v.current=1;
			v.total=1;
			this.setPage(1,1);
			this.addEventHandler('mousedown', '_mousedown');
		},
		styleFor:function(element,id){
		},
		_mousedown:function(event){
			var id=event.target.id;
			if(id=='xlvid_next_page'){
				this.nextPage(1);
			}
			if(id=='xlvid_prev_page'){
				this.nextPage(-1);
			}
			if(id=='xlvid_next_flip'){
				this.flipPages(true);
			}
			if(id=='xlvid_prev_flip'){
				this.flipPages(false);
			}
			if(id=='xlvid_page'){
				this.$V.current=parseInt(event.target.innerHTML);
				this._arrangePages();
				this.showPage(this.$V.current);
			}
		},
		setPageText:function(){
			var p=this.$P,v=this.$V;
			v.pageText.innerHTML=p.currentPageText+' '+v.current+p.separator+v.total+' '+p.totalPageText;
		},
		setPage:function(current,total,showpage){
			var v=this.$V;
			total=(total)?total:v.total;
			current=(current>total)?total:current;
			v.current=current;
			v.total=total;
			this._arrangePages();
			if(showpage)this.showPage(v.current);
		},
		_arrangePages:function(first){
			var v=this.$V,p=this.$P;
			if(!first){
				first=parseInt(v.pages[0].innerHTML);
				if(v.current > first+(p.pages-1)) first=v.current-(p.pages-1);
				else if(v.current < first) first=v.current;
			}
			var last=first;	
			for(var i=0; i < p.pages;++i){
				var page=v.pages[i];
				Element.removeClassName(page,'current_page');
				if(first+i > v.total){
					page.style.display='none';
					continue;
				}
				page.style.display='';
				page.innerHTML=first+i;
				if(first+i == v.current) Element.addClassName(page,'current_page');
				last=first+i;
			}
			v.nextFlip.style.display=(v.total != last)?'':'none';
			v.prevFlip.style.display=(first > 1) ? '' :'none';
			Element.removeClassName(this,'wait');
			this.setPageText();
		},
		flipPages:function(next){
			var v=this.$V,p=this.$P;
			var first=parseInt(v.pages[0].innerHTML);
			if(next){
				first += p.pages;
				if(first+p.pages > v.total) first=v.total-(p.pages-1);
			}else {
				first -= p.pages;
				if(first < 1) first=1;
			}
			this._arrangePages(first);
		},
		nextPage:function(offset){
			var page=parseInt(this.$V.current)+offset;
			if(page < 1 || page > this.$V.total) return;
			this.$V.current=page;
			this._arrangePages();
			this.showPage(this.$V.current);
		},
		showPage:function(page_no){
			
		}
	}
};
